package com.websocket.demo.server.impl;

import com.websocket.demo.controller.WebSocket;
import com.websocket.demo.server.WebSocketServer;
import org.springframework.stereotype.Service;

import java.io.IOException;

/**
 * @author lirenchun
 */
@Service
public class WebSocketServerImpl implements WebSocketServer {
    @Override
    public void sendToUserByUserName(String userName, String msg) throws IOException {
        //获取用户的webSocket对象
        WebSocket ws = WebSocket.getClients().get(userName);
        //发送消息
        ws.sendMessage(msg);
    }
}
